package com.tanhua.admin.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.db.Analysis;
import org.apache.ibatis.annotations.Select;

public interface AnalysisMapper extends BaseMapper<Analysis> {
    @Select("select * from tb_analysis_by_day where record_date=#{date}")
    Analysis findByRecordDate(String date);


    //累计注册用户数
    @Select("select sum(num_registered) from tb_analysis_by_day")
    Long totalUser();

    /**
     * 根据大于传入时间统计数量
     * @param offsetDay
     * @return
     */
    @Select("select sum(num_active) from tb_analysis_by_day where record_date > #{offsetDay}")
    long countActive(DateTime offsetDay);


    /**
     * 今日 昨天 新增用户数量
     * @param date
     * @return
     */
    @Select("select num_registered from tb_analysis_by_day where record_date = #{date}")
    Long countNewUsers(String date);

    /**
     * 今日 昨天 登录次数
     * @param date
     * @return
     */
    @Select("select num_login from tb_analysis_by_day where record_date = #{date}")
    Long countLoginTimes(String date);

    /**
     * 今日 昨天 活跃用户数量
     * @param date
     * @return
     */
    @Select("select num_active from tb_analysis_by_day where record_date = #{date}")
    Long countActiveUsers(String date);
}